package com.itheima;

import java.nio.charset.StandardCharsets;
import java.util.*;

import com.alibaba.fastjson.JSON;
import com.heima.file.service.FileStorageService;
import com.heima.wemedia.WemediaApplication;
import org.json.JSONArray;
import org.json.JSONObject;
import com.baidu.aip.ocr.AipOcr;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest(classes = WemediaApplication.class)
@RunWith(SpringRunner.class)
public class Sample {

    @Autowired
    private FileStorageService fileStorageService;
    //设置APPID/AK/SK
    public static final String APP_ID = "31326206";
    public static final String API_KEY = "gcpS5NYi0kcYrRDbnOhAeDMU";
    public static final String SECRET_KEY = "01bDCu7d8G8qW2HbIIqqCvHHe6oWlwsL";


    @Test
    public void Test1() {
        // 初始化一个AipOcr
        AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);

        // 调用接口
        String path = "E:\\R-C.png";
        JSONObject res = client.basicGeneral(path, new HashMap<String, String>());
        JSONArray result = res.getJSONArray("words_result");
        List<Object> objects = result.toList();
        StringBuilder stringBuilder = new StringBuilder();
        for (Object o : objects) {
            Map<String, String> map = (Map<String, String>) o;
            String words = map.get("words");
            stringBuilder.append(words);
        }
        System.out.println(stringBuilder);
    }
}
